VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmMain 
   Caption         =   "CPU Load Display"
   ClientHeight    =   2880
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3090
   ScaleHeight     =   2880
   ScaleWidth      =   3090
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdStop 
      Caption         =   "Stop"
      Enabled         =   0   'False
      Height          =   495
      Left            =   600
      TabIndex        =   3
      Top             =   2160
      Width           =   1935
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "Start"
      Height          =   495
      Left            =   600
      TabIndex        =   2
      Top             =   1560
      Width           =   1935
   End
   Begin VB.ListBox lstComport 
      Height          =   840
      Left            =   1200
      TabIndex        =   1
      Top             =   360
      Width           =   1335
   End
   Begin MSCommLib.MSComm COM 
      Left            =   1920
      Top             =   2160
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Timer tmrTimer1 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   2040
      Top             =   1680
   End
   Begin VB.Label Label1 
      Caption         =   "COM Port:"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   1095
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private CpuObject As Object
Dim COMoutput As String
Dim CPUusage As Integer
Dim ValsArray(10) As String




Sub minimize_to_tray()
    Me.Hide
   ' nid.cbSize = Len(nid)
   ' nid.hwnd = Me.hwnd
   ' nid.uId = vbNull
   ' nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
   ' nid.uCallBackMessage = WM_MOUSEMOVE
   ' nid.hIcon = Me.Icon ' the icon will be your Form1 project icon
    'nid.szTip = "blablabla text u want to show when mouse over tray iicon" & vbNullChar
    'Shell_NotifyIcon NIM_ADD, nid
End Sub


Private Sub cmdStart_Click()
   tmrTimer1_Timer
   tmrTimer1.Enabled = True
   cmdStart.Enabled = False
   cmdStop.Enabled = True
   minimize_to_tray
End Sub

Private Sub cmdStop_Click()
    tmrTimer1.Enabled = False
    cmdStart.Enabled = True
    cmdStop.Enabled = False
End Sub

Private Sub Form_Load()
    ValsArray(0) = "p"
    ValsArray(1) = "q"
    ValsArray(2) = "r"
    ValsArray(3) = "s"
    ValsArray(4) = "t"
    ValsArray(5) = "u"
    ValsArray(6) = "v"
    ValsArray(7) = "w"
    ValsArray(8) = "x"
    ValsArray(9) = "y"
    
    lstComport.AddItem "Com 1"
    lstComport.AddItem "Com 2"
    lstComport.AddItem "Com 3"
    lstComport.AddItem "Com 4"
    lstComport.AddItem "Com 5"
    lstComport.AddItem "Com 6"
    lstComport.AddItem "Com 7"
    lstComport.AddItem "Com 8"
    lstComport.AddItem "Com 9"
    
    lstComport.ListIndex = 0


    If COM.PortOpen = False Then
        COM.PortOpen = True
    End If

  ' CPU
  If IsWinNT Then
    Set CpuObject = New clsCPUUsageNT
  Else
    Set CpuObject = New clsCPUUsage
  End If
  CpuObject.Initialize

End Sub

Private Sub lstComport_Click()
    On Error Resume Next
    COM.PortOpen = False
    COM.CommPort = lstComport.ListIndex + 1
    COM.PortOpen = True
End Sub

Private Sub tmrTimer1_Timer()
  Dim lCpuUsage As Long
  
  On Error Resume Next
  
  lCpuUsage = CpuObject.Query
  CPUusage = lCpuUsage
  If (CPUusage = 100) Then
    CPUusage = 99
  End If
  
  
  If lCpuUsage <> -1 Then
    COMoutput = CPUusage - Fix(CPUusage / 10) * 10 'Send value
    COM.Output = COMoutput
    
    COMoutput = ValsArray(Fix(CPUusage / 10))
    COM.Output = COMoutput
  End If
  
End Sub
